package com.jf.yytgd.validation.validator;

import com.jf.yytgd.validation.constrain.Title;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

/**
 * Created with IntelliJ IDEA
 * Description: Title验证逻辑实现
 * User:22954
 * Date:2025-01-22
 * Time:21:53
 */
public class TitleValidator implements ConstraintValidator<Title, String> {
    private int limitLength;

    @Override
    public void initialize(Title constraintAnnotation) {
        ConstraintValidator.super.initialize(constraintAnnotation);
        limitLength = constraintAnnotation.max();
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        return value != null && value.codePointCount(0, value.length()) <= limitLength;
    }
}
